﻿using Sustainalytics.Entities;
using System;

namespace Sustainalytics.DataLayer.Tests
{
    public static class EventsTestingData
    {
        public static Event[] EventsLst { get; set; }

        static EventsTestingData()
        {
            EventsLst = new Event[30];

            CreateEvents(0, 10, true, EventStatus.Draft, DateTime.Now.AddDays(-1));
            CreateEvents(10, 20, true, EventStatus.Published, DateTime.Now.AddDays(-1));
            CreateEvents(20, 30, true, EventStatus.Published, DateTime.Now.AddDays(-1));
        }

        private static void CreateEvents(int fromIndex, int toIndexExclusive, bool sponsorship, EventStatus status, DateTime publishedDate)
        {
            for (int index = fromIndex; index < toIndexExclusive; index++)
            {
                Event eventObj = new Event
                {
                    Id = Guid.Parse("00000000-0000-0000-0000-" + (index + 1).ToString().PadLeft(12, '0')),
                    Name = string.Format("UTest The Event {0} Name", index),
                    Body = string.Format("UTest This is Event {0} Body", index),
                    Sponsorship = sponsorship,
                    StartDate = DateTime.Now.AddDays(index),
                    EndDate = DateTime.Now.AddDays(index + 1),
                    Status = status,
                    AddedByUserId = Guid.NewGuid()
                };

                EventsLst[index] = eventObj;
            }
        }

        public static void InitializeRepo(IEventsRepository repo)
        {
            foreach (Event ev in EventsLst)
            {
                repo.AddEvent(ev);
            }
        }

        public static void CleanupRepo(IEventsRepository repo)
        {
            foreach (Event ev in EventsLst)
            {
                repo.DeleteEvent(ev.Id);
            }
        }
    }
}
